using System;
using System.Collections.Generic;
using System.Text;
using Xeml.Document;
using Mpi.Common.Collections;

namespace Xeml.Sampling
{
    public class EventColumnEmitter : ColumnEmitter
    {

        public EventColumnEmitter()
        {
            this._columns = new Dictionary<string, Column>();
            base.name = "Events";
        }
        public override void Emit(Xeml.Document.Contracts.IDocument xemlDoc)
        {
            this._columns.Clear();
            foreach (TreeNode<StoryBase> sbNode in xemlDoc.StoryBoard)
            {
                ExtractCols(sbNode.Content);
            }
        }

        private void ExtractCols(StoryBase sb)
        {
            foreach (Event ev in sb.Events)
            {
                EventColumn ec = new EventColumn();
                ec.Event = ev;
                ec.IsContainerColumn = true;
                ec.Level = EventColumnLevel.Time;
                ec.Enabled = true;
                ec.DataType = typeof(string);
                this._columns.Add(ec.Name, ec);
                foreach (TaggedAnnotation ta in ev.Annotations)
                {
                    EventColumn ec2 = new EventColumn();
                    ec2.Level = EventColumnLevel.Tag;
                    ec2.Event = ev;
                    ec2.Annotation = ta;
                    ec2.IsContainerColumn = false;
                    ec2.Enabled = true;
                    ec2.DataType = typeof(string);
                    ec.SubColumns.Add(ec2.Name, ec2);

                }
                if (ec.SubColumns.Count == 0)
                    ec.IsContainerColumn = false;
            }
        }
    }
}
